package spring.bean;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class BestStudent implements BeanNameAware {
    @Autowired
    private Mali mali;
    @Override
    public void setBeanName(String name) {
        System.out.println("我在加载阶段获得了Bean的名字:"+name);
    }

    public void syncTest() throws InterruptedException{
        System.out.println(Thread.currentThread().getName()+"我是同步执行的方法,开始...");
        mali.sayHello();
        Thread.sleep(3000);
        System.out.println("我是同步执行的方法,结束!");
    }

    @Async
    public void asyncTest() throws InterruptedException {
        System.out.println(Thread.currentThread().getName()+"我是异步执行的方法，开始...");
        Thread.sleep(3000);
        System.out.println("我是异步执行的方法，结束！");
    }
}
